<template>
<Row class="layout-content-body">

  <dtable :columns="columns" :dataAll="dataAll" :totals="total" 
  add check delCheck
  @refresh="getall()" @add="add" @del="del" @edit="edit"  :loading="loading"></dtable>

</Row>
</template>

<script>
import {
  timeFormat
} from '@/common/filter'
import dtable from '@/components/table/dtable.vue' //采用biztable
export default {
  data() {
    return {
      loading: false,  //数据刷新遮罩层
      columns: [
        //多选框
        {
          title: '名称',
          key: 'Name',
          sortable: true
        },
        {
          title: '客户',
          key: 'Cname',
          sortable: true
        },
        {
          title: '金额',
          key: 'DiscountPrice',
          sortable: true
        },
        {
          title: '说明',
          key: 'Remark',
          sortable: true,
        },
        {
          title: '创建人',
          key: 'Creater',
          sortable: true
        },
        {
          title: '创建时间',
          key: 'Ctime',
          sortable: true,
           render: (h, params) => {
            return h('div', [
              h('strong', timeFormat(params.row.Ctime))
            ]);
          }
        },
      ], //表格样式
      dataAll: [], //表格数据来源
      dataShow: true, //是否显示表格数据查看表单
      total: 0,
      tempData:{
        edit:false
      }, 
    }
  },
  components: {
    dtable,
  },
  computed: {

  },
  watch: {},
  methods: {
    getall() {
      this.loading = true
      this.$api.getTemp().then(res => {
        if (!res.error) {
          console.log(res.Data)
          this.dataAll = res.Data
          if (this.dataAll) {
            this.total = (this.dataAll).length
          }
        } else {
          this.$Message.error(res.message)
        }
      })
      setTimeout(() => {
        this.loading = false;
      }, 500);
    },
    edit(index) {
        console.log(index.Id)
        this.tempData.temp =index
        this.tempData.edit = true
          this.$router.push({
            name: '订单模板明细',
            params: {
              tempData: this.tempData
            }
          })
    },
    add() {
      this.tempData.edit = false
      this.$router.push({
        name: '订单模板明细',
        params: {
          tempData: this.tempData
        }
      })
    },
    del(row) {
      this.$api.deleteTemp(row).then(res => {
        if (!res.error) {
          this.getall()
          this.$Message.success(res.message)
        } else {
          this.$Message.error(res.message, 4)
        }
      })
    },
    delCheck(row) {

    },
  },
  mounted() {
    this.getall()
  }
}
</script>
